package vn.raz.brainnydefense.object;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;

import vn.raz.bmspriter.BMSSCMLFile;
import vn.raz.bmspriter.libgdxrenderer.BMSLibgdxAnimationInstance;
import vn.raz.bmspriter.libgdxrenderer.BMSLibgdxRenderer;
import vn.raz.brainnydefense.ultility.Assets;

public class Zombie {
	BMSSCMLFile scml;
	public BMSLibgdxAnimationInstance anim;
	int hp;
	float speed;
	Vector2 movetime;

	public float x, y;
	public boolean isdying;
	
	public Zombie(BMSSCMLFile scml, float x, float y, Vector2 movetime){
		this.scml = scml;
		anim = new BMSLibgdxAnimationInstance(scml.getEntity(0).getAnimation("run"), Assets.zombie_producer );
		this.x = x;
		this.y = y;
		this.movetime = movetime;
		speed = -15;
		hp = 1000;
	}
	
	public void update(float delta){
		anim.animate((int)(delta*1000));
		if(hp>0 && anim.getTime()>movetime.x && anim.getTime()<movetime.y)
			x += speed*delta;
	}
	
	public void takeDamage(int damage){
		hp -= damage;
		if(hp<=0 && !isdying){
			anim = new BMSLibgdxAnimationInstance(scml.getEntity(0).getAnimation("die"), Assets.zombie_producer );
			anim.setLooping(false);
			isdying = true;
		}
	}
	
	public boolean isDead(){
		return isdying && anim.getTime()>=1499;
	}
	
	public void run(){
		
	}
	
	public void attack(){
		
	}
	
	public void die(){
		
	}
	
	public void draw(BMSLibgdxRenderer bmsRenderer){
		bmsRenderer.render(anim, x, y, .6f, false, false);
	}
}
